package thread;

public class SyncDemo2 {
    public static void main(String[] args) {
        shop shop1 = new shop();
        shop shop2 = new shop();
        Thread t1 = new Thread("传奇"){
            @Override
            public void run() {
                shop1.buy();
            }
        };
        Thread t2 = new Thread("史诗"){
            @Override
            public void run() {
                shop2.buy();
            }
        };
        t1.start();
        t2.start();
    }

}
class shop{
    public static void buy(){
        try {
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+":正在挑衣服");
            Thread.sleep(2000);

            synchronized (shop.class){
                System.out.println(t.getName()+":正在试衣服");
                Thread.sleep(2000);
            }

            System.out.println(t.getName()+":结账离开");
        } catch (InterruptedException e) {
            System.out.println("出错了");
        }
    }
}
